package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.SupplierInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.SupplierInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.SupplierInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 供应商管理API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月26日
*
*/
@Validated
@Api(tags = "supplierInfo", description = "供应商管理")
@RestController
@RequestMapping("/supplierInfo")
public class SupplierInfoController{

    @Reference(version = "${service.version}", check = false)
    SupplierInfoService supplierInfoService;

    @RateLimit()
    @ApiOperation("供应商管理信息")
    @PostMapping("/seleteCallAplanInfo")
    public ResultVo seleteCallAplanInfo(@RequestBody SupplierInfoDto callAplanInfoDto){
        PageInfo<SupplierInfo> list = supplierInfoService.seleteSupplierInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新供应商管理")
    @PostMapping("/updatCallAplanInfo")
    public ResultVo updatCallAplanInfo(@ApiParam(value = "supplierInfo", required = true)
                                       @Validated @RequestBody SupplierInfo supplierInfo){
        boolean index = supplierInfoService.updateSupplierInfo(supplierInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加供应商管理")
    @PostMapping("/addCallAplanInfo")
    public ResultVo addCallAplanInfo(@ApiParam(name = "supplierInfo", required = false)
                                     @Validated @RequestBody SupplierInfo supplierInfo){
        boolean list  = supplierInfoService.addSupplierInfo(supplierInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除供应商管理")
    @DeleteMapping("deleteCallAplanInfo/{supId}")
    public ResultVo deleteCallAplanInfo(@NotNull @ApiParam(name = "supId", value = "supId", required = true) @PathVariable String supId){
        boolean b = supplierInfoService.removeSupplierInfo(supId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }

}